﻿using UnityEngine;
using System.Collections.Generic;

namespace Com.ZX
{
	public class CustomDebug
	{
		public static List<string> user = new List<string>();
		private static bool isShowLog = AppConst._isDebugMode;
        //private static bool isWrite2LogFile = true;
		public static void init()
		{
            addLogName("Socket");
			addLogName("Common");
			addLogName("Scene");
		    addLogName("Download");
			addLogName("LoadAssets");
		}

		public static void addLogName(string str)
		{
			if (user.IndexOf(str) == -1)
			{
				user.Add(str);
			}
		}

		private static void log(object message, Object context = null)
		{
			Debug.Log(">>>>>>>>> " + message, context);
		}
		private static void logError(object message)
		{
			Debug.LogError(">>>>>>>>> " + message);
		}
		private static void logWarning(object message)
		{
			Debug.LogWarning(">>>>>>>>> " + message);
		}

		public static void Log(object message, string logName = "Common", Object context = null)
		{
			if (isShowLog)
			{
				if (user.IndexOf(logName) > -1)
				{
					try
					{
						if (context != null)
						{
							log(message, context);
						}
						else {
							log(message);
						}
					}
					catch (System.Exception e)
					{
						logError(e.Message + e.StackTrace);
					}
				}
			}
		}

		public static void LogError(object message, string logName = "Common")
		{
			if (isShowLog)
			{
				if (user.IndexOf(logName) > -1)
				{
					logError(message);
				}
			}
		}


		public static void LogWarning(object message, string logName = "Common")
		{
			if (isShowLog)
			{
				if (user.IndexOf(logName) > -1)
				{
					logWarning(message);
				}
			}
		}

		public static void LogInScene(object message)
		{
			Log(message, "Scene");
		}

        public static void LogToTxtFile(object message, string path)
        {
            //TO DO output the log to a txt file
            //File
            //using ()
        }
	}
}